package emulator.analyzer.util;

import java.util.Collection;
import java.util.HashMap;
import java.util.TreeMap;

public class CmpCommandMap {
	HashMap<Integer, TreeMap<Integer, CmpCommand> > cmp_map = new HashMap<Integer, TreeMap<Integer, CmpCommand> >();

	public void add(CmpCommand cmp)
	{
		TreeMap<Integer, CmpCommand> map_entry = null;
		if (cmp_map.containsKey(cmp.getRegSource()))
			map_entry = cmp_map.get(cmp.getRegSource());
		else
		{
			map_entry = new TreeMap<Integer, CmpCommand>();
			cmp_map.put(cmp.getRegSource(), map_entry);
		}
		if (!map_entry.containsKey(cmp.getLocation()))
			map_entry.put(cmp.getLocation(), cmp);
	}
	
	public Collection<CmpCommand> get(Integer reg_source)
	{
		TreeMap<Integer, CmpCommand> map_entry = cmp_map.get(reg_source);
		return (map_entry != null ? map_entry.values(): null);
	}

}
